home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / mathpack / sgedi.f < prev    next >
Text File  |  1989-08-17  |  4KB  |  129 lines

  1.       subroutine sgedi(a,lda,n,ipvt,det,work,job)                       
  2.       integer lda,n,ipvt(1),job
  3.       real a(lda,1),det(2),work(1)
  4. c
  5. c     sgedi computes the determinant and inverse of a matrix
  6. c     using the factors computed by sgeco or sgefa.
  7. c
  8. c     on entry
  9. c
  10. c        a       real(lda, n)
  11. c                the output from sgeco or sgefa.
  12. c
  13. c        lda     integer
  14. c                the leading dimension of the array  a .
  15. c
  16. c        n       integer
  17. c                the order of the matrix  a .
  18. c
  19. c        ipvt    integer(n)
  20. c                the pivot vector from sgeco or sgefa.
  21. c
  22. c        work    real(n)
  23. c                work vector.  contents destroyed.
  24. c
  25. c        job     integer
  26. c                = 11   both determinant and inverse.
  27. c                = 01   inverse only.
  28. c                = 10   determinant only.
  29. c
  30. c     on return
  31. c
  32. c        a       inverse of original matrix if requested.
  33. c                otherwise unchanged.
  34. c
  35. c        det     real(2)
  36. c                determinant of original matrix if requested.
  37. c                otherwise not referenced.
  38. c                determinant = det(1) * 10.0**det(2)
  39. c                with  1.0 .le. abs(det(1)) .lt. 10.0
  40. c                or  det(1) .eq. 0.0 .
  41. c
  42. c     error condition
  43. c
  44. c        a division by zero will occur if the input factor contains
  45. c        a zero on the diagonal and the inverse is requested.
  46. c        it will not occur if the subroutines are called correctly
  47. c        and if sgeco has set rcond .gt. 0.0 or sgefa has set
  48. c        info .eq. 0 .
  49. c
  50. c     linpack. this version dated 08/14/78 .
  51. c     cleve moler, university of new mexico, argonne national lab.
  52. c
  53. c     subroutines and functions
  54. c
  55. c     blas saxpy,sscal,sswap
  56. c     fortran abs,mod
  57. c
  58. c     internal variables
  59. c
  60.       real t
  61.       real ten
  62.       integer i,j,k,kb,kp1,l,nm1
  63. c
  64. c
  65. c     compute determinant
  66. c
  67.       if (job/10 .eq. 0) go to 70
  68.          det(1) = 1.0e0
  69.          det(2) = 0.0e0
  70.          ten = 10.0e0
  71.          do 50 i = 1, n
  72.             if (ipvt(i) .ne. i) det(1) = -det(1)
  73.             det(1) = a(i,i)*det(1)
  74. c        ...exit
  75.             if (det(1) .eq. 0.0e0) go to 60
  76.    10       if (abs(det(1)) .ge. 1.0e0) go to 20
  77.                det(1) = ten*det(1)
  78.                det(2) = det(2) - 1.0e0
  79.             go to 10
  80.    20       continue
  81.    30       if (abs(det(1)) .lt. ten) go to 40
  82.                det(1) = det(1)/ten
  83.                det(2) = det(2) + 1.0e0
  84.             go to 30
  85.    40       continue
  86.    50    continue
  87.    60    continue
  88.    70 continue
  89. c
  90. c     compute inverse(u)
  91. c
  92.       if (mod(job,10) .eq. 0) go to 150
  93.          do 100 k = 1, n
  94.             a(k,k) = 1.0e0/a(k,k)
  95.             t = -a(k,k)
  96.             call sscal(k-1,t,a(1,k),1)
  97.             kp1 = k + 1
  98.             if (n .lt. kp1) go to 90
  99.             do 80 j = kp1, n
  100.                t = a(k,j)
  101.                a(k,j) = 0.0e0
  102.                call saxpy(k,t,a(1,k),1,a(1,j),1)
  103.    80       continue
  104.    90       continue
  105.   100    continue
  106. c
  107. c        form inverse(u)*inverse(l)
  108. c
  109.          nm1 = n - 1
  110.          if (nm1 .lt. 1) go to 140
  111.          do 130 kb = 1, nm1
  112.             k = n - kb
  113.             kp1 = k + 1
  114.             do 110 i = kp1, n
  115.                work(i) = a(i,k)
  116.                a(i,k) = 0.0e0
  117.   110       continue
  118.             do 120 j = kp1, n
  119.                t = work(j)
  120.                call saxpy(n,t,a(1,j),1,a(1,k),1)
  121.   120       continue
  122.             l = ipvt(k)
  123.             if (l .ne. k) call sswap(n,a(1,k),1,a(1,l),1)
  124.   130    continue
  125.   140    continue
  126.   150 continue
  127.       return
  128.       end
  129.